<?php
	require_once '../lib/controller.php';

	class action extends controller
	{
		var $db;

		function do_get()
		{
			$this->visit_log();
			$location = $this->get['uri'];
			$location = str_replace("&amp;", "&", $location);

			header('Location: ' .  $location);
		}

		function check_get()
		{
			$this->get['uri'] = urldecode( $this->get['uri'] );

			if( empty($this->get['uri']) || empty( $this->get['id'] ) )
			{
				$this->msg('参数不能为空');

				return false;
			}

			if( ! preg_match('/^http:\/\//', $this->get['uri']) )
			{
				$this->msg('参数错误');

				return false;
			}

			return true;
		}

		function visit_log()
		{
			$this->db = $this->module('lib.db');
			$article_id = intval( $this->get['id'] );
			$url_hash = md5($this->get['uri']);
			$ctime = time();
			$ip = ip2long($this->server['REMOTE_ADDR']);
			$sql = "insert into meye_article_visit_log (article_id, url_hash, ctime, ip)  values ('$article_id', '$url_hash',$ctime,'$ip') ";
			$this->db->query($sql);
		}

		function error($msg)
		{
			die($msg);
		}

	}

	$obj = new action();
	$obj->run();
?>